<?php
    
    namespace App\Http\Requests;
    
    use Illuminate\Foundation\Http\FormRequest;
    
    class GoodsRequest extends FormRequest
    {
        public function authorize()
        {
            return auth('admin')->check();
        }
        
        public function rules()
        {
            return [
                'name' => 'required',
                'brief' => 'required',
                'price' => 'required|numeric',
                'classify_id' => function ($attributr, $value, $fail) {
                    if (in_array(null, $value)) {
                        return $fail('请选择分类');
                    }
                },
                'attribute' => 'required',
                'pictures' => 'required',
                'details' => 'required',
            ];
        }
        public function messages()
        {
            return [
                'name.required' => '商品名称不能为空',
                'brief.required' => '商品简介不能为空',
                'price.required' => '商品价格不能为空',
                'price.numeric' => '商品价格必须是数字',
                'price.alpha_num' => '请正确填写商品价格',
                'pictures.required' => '请上传商品图片',
                'attribute.required' => '请选择商品属性',
                'details.required' => '请填写商品详情',
            ];
        }
    }
